package org.imraniqbal.frogger;

import org.imraniqbal.engine.Direction;
import org.imraniqbal.engine.Map;
import org.imraniqbal.engine.Player;
/**
 * Car - these are the cars that frogger will have to dodge in order to get to his flower and back
 * @author  Colin MacDougall unless otherwise specified
 */
public class Car extends Player{
	/**
	 * @uml.property  name="iD"
	 */
	private int ID;
	
	public Car(int x, int y, Direction direction, int numOflives, int iD) {
		super(x, y, direction, numOflives);
		setID(iD);
	}

	@Override
	public void spawn(Map map) {
		map.addMappable(this);
	}

	/**
	 * @param iD  the iD to set
	 * @author  imran
	 * @uml.property  name="iD"
	 */
	public void setID(int iD) {
		ID = iD;
	}

	/**
	 * @return  the iD
	 * @author  imran
	 * @uml.property  name="iD"
	 */
	public int getID() {
		return ID;
	}
	
	public void moveCar(Map map){
		while(!updateLocation(map)){
			if(this.getDirection() == Direction.LEFT){
				this.setX(18);
			}
			else if(this.getDirection() == Direction.RIGHT)
			{
				this.setX(0);
			}
		}
	}
	
	/**
	 * @author imran
	 */
	@Override
	public boolean equals(Object obj) {
		if(obj instanceof Car){
			if(((Car)obj).getX() == this.getX() && ((Car)obj).getY() == this.getY()){
				return( ((Car)obj).getDirection() == this.getDirection() &&
						((Car)obj).getID() == this.getID());
			}
		}
		return false;
	}
}
